package com.m3958.firstgwt.client.window;

import com.google.inject.Singleton;
import com.smartgwt.client.types.Alignment;
import com.smartgwt.client.widgets.IButton;
import com.smartgwt.client.widgets.Label;
import com.smartgwt.client.widgets.Window;
import com.smartgwt.client.widgets.events.ClickEvent;
import com.smartgwt.client.widgets.events.ClickHandler;
import com.smartgwt.client.widgets.layout.HLayout;
import com.smartgwt.client.widgets.layout.VLayout;

@Singleton
public class HelpLinkWindow extends Window{


	private boolean initialized = false;
	private Label label;
	
	public HelpLinkWindow(){
		setWidth(300);
		setHeight(150);
		setIsModal(true);
		setShowModalMask(true);
		setTitle("帮助");
		centerInPage();
	}
	
	public HelpLinkWindow showMe(String description,String url){
		if(!initialized){
			initialized = true;
			VLayout layout = new VLayout(5);
			label = new Label();
			layout.addMember(label);
			label.setWidth100();
			label.setHeight(50);
			label.setAlign(Alignment.CENTER);
			layout.addMember(initBt());
			addItem(layout);
		}
		label.setContents("<a href=\"" + url + "\" target=\"_blank\">" + description + "</a>");
		show();
		return this;
	}
	

	private HLayout initBt() {
		HLayout hl = new HLayout();
		hl.setHeight(25);
		hl.setAlign(Alignment.RIGHT);
		IButton ib = new IButton("关闭");
		ib.addClickHandler(new ClickHandler() {
			@Override
			public void onClick(ClickEvent event) {
				HelpLinkWindow.this.hide();
			}
		});
		hl.addMember(ib);
		return hl;
	}
}
